package com.solo.system.mapper;

import com.mybatisflex.core.query.QueryChain;
import com.solo.common.core.base.mapper.BasicMapper;
import com.solo.system.api.consts.global.GlobalStatus;
import com.solo.system.api.entity.SysDictData;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

import static com.solo.system.api.entity.table.SysDictDataTableDef.SysDictDataTable;
import static com.solo.system.api.entity.table.SysDictTypeTableDef.SysDictTypeTable;

/**
 * 字典数据Mapper接口
 * @author 十一
 * @since 2023/09/26 11:27
 * 人生若只如初见，何事秋风悲画扇
 **/
@Mapper
public interface SysDictDataMapper extends BasicMapper<SysDictData> {
    
    default List<SysDictData> selectByCode(String code) {
        return QueryChain.of(this)
                .select(SysDictDataTable.DefaultColumns)
                .from(SysDictTypeTable)
                .leftJoin(SysDictDataTable)
                .on(SysDictTypeTable.Code.eq(SysDictDataTable.Code))
                .where(SysDictTypeTable.Code.eq(code).and(SysDictTypeTable.Status.eq(GlobalStatus.NORMAL)))
                .orderBy(SysDictDataTable.DictSort.asc())
                .list();
    }

}
